package com.geostar.constructionland.analyse.entity.resulthandler;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @author yelll
 * @since 2020-6-8 17:03
 **/
public class  HandlerResult<T> {
    private int status;
    private String message;
    private T data;
    public HandlerResult(){

    }
    private HandlerResult(int status) {
        this.status = status;
    }

    public HandlerResult(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public HandlerResult(int status, T data) {
        this.status = status;
        this.data = data;
    }

    private HandlerResult(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;

    }

    public void setMessage(String message) {
        this.message = message;
    }

    @JsonIgnore
    public boolean isSuccess() {
        return this.status == ResultHandlerCode.SUCCESS.getCode();
    }

    public int getStatus() {
        return status;
    }

    public T getData() {
        return data;
    }

    public HandlerResult setData(T data) {
        this.data = data;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public static <T> HandlerResult<T> createBySuccess() {
        return new HandlerResult<T>(ResultHandlerCode.SUCCESS.getCode(), ResultHandlerCode.SUCCESS.getDesc());
    }

    public static <T> HandlerResult<T> createBySuccessMessage(String message) {
        return new HandlerResult<T>(ResultHandlerCode.SUCCESS.getCode(), message);
    }

    public static <T> HandlerResult<T> createBySuccess(T data) {
        return new HandlerResult<T>(ResultHandlerCode.SUCCESS.getCode(), ResultHandlerCode.SUCCESS.getDesc(), data);
    }

    public static <T> HandlerResult<T> createBySuccess(String message, T data) {
        return new HandlerResult<T>(ResultHandlerCode.SUCCESS.getCode(), message, data);
    }

    public static <T> HandlerResult<T> createByError() {
        return new HandlerResult<T>(ResultHandlerCode.ERROR.getCode(), ResultHandlerCode.ERROR.getDesc());
    }

    public static <T> HandlerResult<T> createByErrorMessage(String errorMessage) {
        return new HandlerResult<T>(ResultHandlerCode.ERROR.getCode(), errorMessage);
    }

    public static <T> HandlerResult<T> createByErrorCodeMessage(int errorCode, String errorMessage) {
        return new HandlerResult<T>(errorCode, errorMessage);
    }

    public static <T> HandlerResult<T> createBySpatiaAnalyse_error(String errorMessage,T data) {
        return new HandlerResult<T>(ResultHandlerCode.SPT_ANALYST_ERROR.getCode(), errorMessage,data);
    }

    public static <T> HandlerResult<T> createByHave_overlap_land_error(String errorMessage,T data) {
        return new HandlerResult<T>(ResultHandlerCode.HAVE_OVERLAP_LAND_ERROR.getCode(), errorMessage,data);
    }
}

